﻿using Dapper;
using Entity;
using IRepository;
using System;
using System.Collections.Generic;
using System.Data;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Repository
{
    public class SysDictDataRepository : ISysDictDataRepository
    {
        private readonly string _connectionString;

        public SysDictDataRepository(string connectionString)
        {
            _connectionString = connectionString;
        }

        public async Task<List<SysDictData>> GetAllNormalDictDatasAsync()
        {
            using (IDbConnection db = new SqlConnection(_connectionString))
            {
                string sql = "SELECT * FROM wms_Dictionary_data WHERE Status = '0' ORDER BY DictTypeCode, Sort ASC";
                return (await db.QueryAsync<SysDictData>(sql)).ToList();
            }
        }

        public async Task<List<SysDictData>> GetDictDatasByTypeCodeAsync(string dictTypeCode)
        {
            using (IDbConnection db = new SqlConnection(_connectionString))
            {
                string sql = "SELECT * FROM wms_Dictionary_data WHERE DictTypeCode = @DictTypeCode AND Status = '0' ORDER BY Sort ASC";
                return (await db.QueryAsync<SysDictData>(sql, new { DictTypeCode = dictTypeCode })).ToList();
            }
        }
    }
}
